package com.lambda.hybrid.handler;

import android.content.SharedPreferences;

import com.lambda.hybrid.Callback;

import org.json.JSONObject;

public class GetStorageHandler extends AbstractHandler {
    private final SharedPreferences mSharedPre;

    public GetStorageHandler(SharedPreferences storage) {
        mSharedPre = storage;
    }

    @Override
    public void onHandle(String data, Callback callback) throws Exception {
        JSONObject table = new JSONObject(data);
        JSONObject resp = new JSONObject();
        String value = mSharedPre.getString(table.getString("key"), null);
        resp.put("value", value == null ? JSONObject.NULL : value);
        callback.invoke(resp.toString());
    }
}
